﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Linq;

using NHibernate.Criterion;

using ProjectBase.Core;
using ProjectBase.Data;
using ProjectBase.Data.NH;

using $prjsn$.Common.Data;
using $prjsn$.Entity;

namespace $safeprojectname$
{
    public abstract class CodeListDao<TEntity, TFilter>
        : BaseDao<TEntity, int, TFilter>
        , ICodeListDao<TEntity, TFilter>
        where TEntity : class, ICodeList
        where TFilter : CodeListFilter, new()
    {
        /// <summary>
        ///     Returns all Values.
        ///     On upper layer (e.g. Facade) it could be filtered for comboboxes
        ///     using the property IsVisible == true
        /// </summary>
        /// <returns></returns>
        public virtual IEnumerable<TEntity> GetAll()
        {
            return Find(new TFilter { TakeRows = int.MaxValue });
        }

        #region IApplyFilterToCriteria

        protected override IList<ICriterion> Apply(TFilter filter)
        {
            var restrictions = base.Apply(filter);

            // Equal
            restrictions.AddCompare(filter, f => f.IdExact); // Searches for exact ID
            restrictions.AddIn(filter, f => f.IDColl);

            restrictions.AddEqual(filter, f => f.DescriptionExact); // Searches for exact match
            restrictions.AddEqual(filter, f => f.CodeExact); // Searches for exact match

            // Like
            restrictions.AddLike(filter, f => f.Description);
            restrictions.AddLike(filter, f => f.Code);

            // Bool
            restrictions.AddCompare(filter, f => f.IsVisible);

            return restrictions;
        }

        #endregion IApplyFilterToCriteria
    }
}